package com.example.emoiticon.adapter;



import java.io.IOException;

import com.example.emoiticon.R;



import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter{
	  private Context mContext;
	  private int[] tagCollection;

	 /* public Integer[] imagesIds = {R.raw.ani0,R.raw.ani1,R.raw.ani2,R.raw.ani3,
			  R.raw.ani4,R.raw.ani5,R.raw.ani6,R.raw.ani7,
			  R.raw.ani8,R.raw.ani9,R.raw.ani10,R.raw.ani11,
			  R.raw.ani12,R.raw.ani13,R.raw.ani14,R.raw.ani15,
			  R.raw.ani16,R.raw.ani17,R.raw.ani18,R.raw.ani19,R.raw.ani20};*/
		GifAnimationDrawable title;
		 private final int[] imagesIds;
	    public ImageAdapter(Context c, int[] imagesIds2) {
	        mContext = c;
	        this.imagesIds=imagesIds2;
	        
	    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imagesIds.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return imagesIds[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return imagesIds[position];
	}
	public int getTagFromPosition(int position)
	{
		return imagesIds[position];
	}

	@SuppressLint("ViewHolder") @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		/*ImageView imageView;
	    if (convertView == null) {
	        imageView = new ImageView(mContext);
	                imageView.setLayoutParams(new GridView.LayoutParams(100, 100));
	        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
	        imageView.setPadding(8, 8, 8, 8);
	    } else {
	        imageView = (ImageView) convertView;
	    }*/
		 View grid;
	      LayoutInflater inflater = (LayoutInflater) mContext
	        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	          if (convertView == null) {
	            grid = new View(mContext);
	            grid = inflater.inflate(R.layout.columns_grid, null);
	          
	            ImageView imageView = (ImageView)grid.findViewById(R.id.imageAnimationCell);
	            try {
	    	        
	    			title=new GifAnimationDrawable(mContext.getResources().openRawResource(imagesIds[position]));
	    			//title.start();
	            	
	    		 }catch(IOException ioe){
	    				
	    			}
	            title.start();
	            imageView.setImageDrawable(title);
	            title.setVisible(true, true);
	            //imageView.setImageResource(imagesIds[position]);
	          } else {
	            grid = (View) convertView;
	            
	          }
	      return grid;
		
	  
	    
	}

}
